<div id="resouce_tree_panel_page" class="demo-tree"></div>

<script>
    layui.use(['tree', 'layer','laytpl'], function () {
        let $ = layui.$
            , layer = layui.layer
            , formUtil = layui.form
            , treeUtil = layui.tree
            , laytplUtil = layui.laytpl;
        _initTreePanel(treeUtil,laytplUtil)

    });

    /**
     * 初始化树组件面板
     * @param tree 树组件
     * @private
     */
    function _initTreePanel(tree, laytpl, form) {
        let data1 = [{
            title: '江西'
            , id: 1
            , children: [{
                title: '南昌'
                , id: 1000
                , children: [{
                    title: '青山湖区'
                    , id: 10001
                }, {
                    title: '高新区'
                    , id: 10002
                }]
            }, {
                title: '九江'
                , id: 1001
            }, {
                title: '赣州'
                , id: 1002
            }]
        }, {
            title: '广西'
            , id: 2
            , children: [{
                title: '南宁'
                , id: 2000
            }, {
                title: '桂林'
                , id: 2001
            }]
        }, {
            title: '陕西'
            , id: 3
            , children: [{
                title: '西安'
                , id: 3000
            }, {
                title: '延安'
                , id: 3001
            }]
        }];

        layui.admin.req({
            url: '/api/resources/tree',
            // data: data,
            type: 'get',
            dataType: 'json',
            contentType: "application/json",
            success: function (res) {
                console.log(JSON.stringify(res.data));
                tree.render({
                    elem: "#resouce_tree_panel_page"
                    , data: res.data
                    , onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
                    , click: function (obj) {
                        getTreeData(obj.data, laytpl, form)
                    }
                });
            },
            error: function (res) {
                layui.view.error('操作失败');
            }
        });
    }

    function getTreeData(data, laytpl, form) {
        // 关闭当前页面
        layer.close(layer.index);
        // 调用父页面方法
        parent.getTreeChooseData(data); //这是父页面函数
    }
</script>